import React, { useState, useEffect, useCallback } from 'react'
import { useHistory } from 'react-router-dom'
import { putAccBidingAddBiding } from '../../../../financialApi'
import {getSysUserSelected} from '../../../../../../Api/listUrl'
import { Button, Form, Input, Select, InputNumber, message, Radio } from 'antd'

const { Option } = Select;
const { TextArea } = Input;

/**
 * @description: 财务-标书费用申请  
 * @author: xiaoxujs
 * @upDate: xiaoxujs（2021-07-07） 
 */

const Tender = () => {
    const history = useHistory()
    const [buttonLoading, setButtonLoading] = useState(false)
    const [userList, setUserList] = useState([])
    const userFun = useCallback(
        () => {
            (async () => {
                const {code, msg, data} = await getSysUserSelected()
                if(code === '20000') {
                    setUserList(data)
                }else{
                    message.error(msg)
                }
            })()
        },
        [],
    )
    useEffect(() => {
        userFun()
    }, [userFun])
    const onFinish = (values) => {
        ; (async () => {
            setButtonLoading(true)
            const { code, msg } = await putAccBidingAddBiding(values)
            if (code === '20000') {
                message.success('提交成功')
                setButtonLoading(false)
                history.go('-1')
            } else {
                setButtonLoading(false)
                message.error(msg)
            }
        })()
    };
    return <Form
        labelCol={{ span: 3 }}
        wrapperCol={{ span: 16 }}
        onFinish={onFinish}
    >
                <Form.Item
            label="申请人"
            name="applicant"
            rules={[{ required: true, message: '请选择申请人!' }]}
        >
            <Select>
                {
                    userList.map(item => <Option value={item.id} key={item.id}>{item.name}</Option>)
                }
            </Select>
        </Form.Item>
        <Form.Item
            label="部门主管"
            name="director"
            rules={[{ required: true, message: '请选择部门主管!' }]}
        >
            <Select>
                {
                    userList.map(item => <Option value={item.id} key={item.id}>{item.name}</Option>)
                }
            </Select>
        </Form.Item>
        <Form.Item
            label="业务人员"
            name="account"
            rules={[{ required: true, message: '请选择业务人员!' }]}
        >
            <Select>
                {
                    userList.map(item => <Option value={item.id} key={item.id}>{item.name}</Option>)
                }
            </Select>
        </Form.Item>
        <Form.Item
            label="发票"
            name="isTicket"
            rules={[{ required: true, message: '请选择是否有发票!' }]}
        >
            <Radio.Group >
                <Radio value={0}>有票</Radio>
                <Radio value={1}>无票</Radio>
            </Radio.Group>
        </Form.Item>

        <Form.Item
            label="标书项目"
            name="item"
            rules={[{ required: true, message: '请输入标书项目!' }]}
        >
            <Input />
        </Form.Item>
       
        <Form.Item
            label="申请事由"
            name="matter"
            rules={[{ required: true, message: '请输入申请事由!' }]}
        >
            <TextArea />
        </Form.Item>
        <Form.Item
            label="申请金额（元）"
            name="money"
            rules={[{ required: true, message: '请输入申请金额!' }]}
        >
            <InputNumber />
        </Form.Item>

        <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
            <Button type="primary" htmlType="submit" loading={buttonLoading}>
                提交申请
            </Button>
        </Form.Item>
    </Form>
}

export default Tender